<template>
  <div class="all">
    <header>
      <div class="div" @click="back">
        <img src="../../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="div">
        <span>{{title}}</span>
      </div>
      <div class="div">
<!--        <span @click="moreDateShow = true" class="solid">{{shaixuanDate}}</span>-->
      </div>
    </header>
    <div class="riqiSelect"  @click="moreDateShow = true">
      <span><a class="hengGang"></a>
        日期选择:
      </span>
      <span style="min-width:50px;justify-content: space-between;margin-left: 8px">
        <a >{{shaixuanDate? shaixuanDate : '请选择'}}</a>
        <img src="../../../assets/下降@2x.png"
             style="width: 13px;height: 7px;margin-left: 8px" alt="">
      </span>
    </div>
    <el-table
      ref="table"
      v-loading="loadingShow"
      element-loading-text="数据正在加载中..."
      :data="tableData"
      border
      @cell-click="handle"
      @selection-change="handleSelectionChange"
      @header-click="tableHeader"
      height="calc(100vh - 44px - 50px - 44px)"
      :header-cell-style="{background:'#1da4f2',color:'#fff',textAlign:'center'}"
      style="width: 100%;font-size: 15px">
      <div slot="empty">
        <div>
          <img src="../../../assets/空两本书.png" alt="" width="140" height="140" />
        </div>
        <p :style="{'marginTop': '5px'}">暂无记录</p>
      </div>
      <el-table-column
        label="序号"
        type="index"
        width="40">
      </el-table-column>
      <el-table-column
        prop="dateday"
        label="日期"
        width="80"
        :render-header="renderHeader"
      >
<!--        :filters="datedaylist"-->
<!--        :filter-method="filterTagDayList"-->
        <template slot-scope="scope">
          <span>{{scope.row.dateday ? scope.row.dateday : '请选择'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="startTime"
        label="起止时间"
        :render-header="renderHeader"
        width="120">
<!--        :filters="startList"-->
<!--        :filter-method="filterTagStart"-->
        <template slot-scope="scope">
          <span>{{scope.row.startTime ? scope.row.startTime + '~' + scope.row.endTime : '请选择'}}</span>
        </template>
      </el-table-column>

      <el-table-column
        v-if="!team_id"
        prop="name"
        label="服务团队"
        align="center"
        :render-header="renderHeader"
        width="110">
        <template slot-scope="scope">
          <span>{{scope.row.team_id == -1 ? scope.row.doc_user_name:
            scope.row.team_id ?
            scope.row.team_name :'空'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="doc_user_name"
        label="服务人员"
        align="center"
        :render-header="renderHeader"
        width="110">
        <template slot-scope="scope">
          <span>{{scope.row.doc_user_name ? scope.row.doc_user_name : '空'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="list"
        label="服务项目"
        :render-header="renderHeader"
        width="150">
<!--        :filters="shaixuanXiangmu"-->
<!--        :filter-method="filterTagXiangmu"-->
        <template slot-scope="scope">
          <div style="display: flex;min-height: 20px;justify-content: space-between">
            <div v-if="scope.row.list && scope.row.list.length > 0" style="display: flex;flex-direction: column;min-width: 80px">
              <p
                  v-for="(item, index) in scope.row.list" :key="index">
                {{index+1}}、{{item.item_id}}
              </p>
            </div>
            <div v-else>无</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-if="patient_user_id == null || patient_user_id == undefined || patient_user_id == ''"
        prop="patient_user_id"
        label="号源情况"
        align="center"
        width="100">
        <template slot-scope="scope">
          <span style="color: red"
                v-if="scope.row.patient_user_id">
            占用</span>
          <span v-else > 空闲</span>
        </template>
      </el-table-column>
    </el-table>
    <van-popup  v-model="hasXiangmuShow"
                round position="bottom"
                :style="{ height: '80%', bottom: '50px'}">
      <header>
        <div class="div solid"><span style="margin-left: 10px" @click="hasXiangmuShow = false">关闭</span></div>
        <div class="div"><span>选择服务项目</span></div>
        <div class="div solid" @click="hasXiangmuShow = false,save(row.list)"><span>确认</span></div>
      </header>
      <div class="pop_content">
        <ul style="width: 100%;padding: 0 10px;box-sizing: border-box">
          <li @click="clickHasPrice(item)"
              style="display: flex;justify-content: space-between" v-for="(item, index) in this.row.list" :key="index">
            <span> {{item.item_id}} （{{
                item.amount_type == 1 ? '图文咨询' :
                  item.amount_type == 2 ? '视频咨询' :
                    item.amount_type == 3 ? '居家康复' :
                      item.amount_type == 4 ? '居家护理' :
                        item.amount_type == 5 ? '远程会诊' :
                          item.amount_type == 6 ? '评定' :
                            item.amount_type == 7 ? '居家生活' : ''
              }}）</span>
            <img class="selectImg" v-if="item.select" src="../../../assets/radio/方形选中.png" alt="">
            <img class="selectImg" v-else src="../../../assets/radio/方形未选中.png" alt="">
          </li>
        </ul>
      </div>
    </van-popup>
    <van-popup  v-model="xiangmuShow"
                round position="bottom"
                :style="{ height: '80%', bottom: '50px' }">
      <header>
        <div class="div solid"><span style="margin-left: 10px" @click="xiangmuShow = false">关闭</span></div>
        <div class="div"><span>选择服务项目</span></div>
        <div class="div solid" @click="priceConfirm()"><span>确认</span></div>
      </header>
      <div class="pop_content">
        <ul style="width: 25%" class="pop_left">
          <li :class="leftIndex == item.type ? 'pop_select': ''"
              v-for="(item, index) in leftMenu"
              :key="index"
              @click="leftIndex = item.type"
          >{{item.name}}</li>
        </ul>
        <ul style="width: 70%;height: 100%;" class="pop_right">
          <li v-for="(item, index) in priceList"
              :key="index"
              @click="clickPrice(item)"
              v-show="leftIndex == item.item_type && item.checked_id"
          >
            <span> {{item.item_id}}</span>
            <img class="selectImg" v-if="item.select" src="../../../assets/radio/方形选中.png" alt="">
            <img class="selectImg" v-else src="../../../assets/radio/方形未选中.png" alt="">
          </li>
        </ul>
      </div>
    </van-popup>
    <van-action-sheet
      @select="selectOpen"
      v-model="isOpenShow"
      :actions="actions"
      cancel-text="取消"
      description="选择类型"
      close-on-click-action
    />
    <van-calendar  color="#1da4f2"
                   v-model="moreDateShow"
                   type="range"
                   :min-date="minDate" :max-date="maxDate"
                   @confirm="moreDateConfirm"
                   :style="{ bottom: '50px' }"
    />
    <pop_select :show="datedayShow"
                title="选择日期"
                height="70%"
                @confirmMethod="filter"
                @close="datedayShow = false"
                :dataList="datedaylist"></pop_select>

    <pop_select :show="start_endShow"
                title="选择起止时间"
                height="70%"
                @confirmMethod="filter"
                @close="start_endShow = false"
                :dataList="startList"></pop_select>
    <pop_select :show="shaixuandoctorShow"
                title="选择服务人员"
                height="70%"
                @confirmMethod="filter"
                @close="shaixuandoctorShow = false"
                :dataList="shaixuandoctor"></pop_select>
    <pop_select :show="shaixuanXiangmuShow"
                title="选择服务项目"
                height="70%"
                @confirmMethod="filter"
                @close="shaixuanXiangmuShow = false"
                :dataList="shaixuanXiangmu"></pop_select>
    <pop_select :show="teamShow"
                title="选择团队名称"
                height="70%"
                @confirmMethod="filter"
                @close="teamShow = false"
                :dataList="teamList"></pop_select>
  </div>
</template>

<script>
import TIME from '../../../assets/Time/Start_EndTime'
import {Toast} from 'vant'
import PopSelect from '../../../components/Vue/PopSelect'
export default {
  name: 'PatientsTable',
  components: {
    pop_select: PopSelect
  },
  data () {
    return {
      timeList: TIME.fifteenColumns,
      Tims: TIME.Times,
      loadingShow: false,
      tableData: [],
      userid: this.$route.query.userid,
      dateday: this.Common.formatDate(new Date(new Date().getTime() + 24 * 60 * 60 * 1000).toLocaleDateString(), 'yyyy-mm-dd'),
      gishuShow: false,
      optionGuishu: [],
      doc_amount_id: '',
      team_amount_id: '',
      row: [],
      xiangmuShow: false,
      leftMenu: [
        {
          name: '图文咨询',
          type: 1
        },
        {
          name: '视频咨询',
          type: 2
        },
        {
          name: '居家康复',
          type: 3
        },
        {
          name: '居家护理',
          type: 4
        },
        {
          name: '远程会诊',
          type: 5
        },
        {
          name: '居家生活',
          type: 7
        }
      ],
      priceList: [],
      leftIndex: 1,
      isOpenShow: false,
      actions: [
        { name: '对内', type: 1 },
        { name: '对外', type: 2 }
      ],
      schedule_typeList: [],
      isLoading: false,
      lastCount: 0,
      nextCount: 0,
      moreDateShow: false,
      start_date: '',
      end_date: '',
      minDate: new Date(2019, 10, 1),
      maxDate: new Date(new Date().getFullYear() + 2, 10, 1),
      shaixuanDate: '',
      team_id: this.$route.query.team_id,
      doc_user_id: this.$route.query.doc_user_id,
      weekOption: [
        {
          text: '星期一',
          value: '星期一'
          // value: '1'
        }, {
          text: '星期二',
          value: '星期二'
          // value: '2'
        }, {
          text: '星期三',
          value: '星期三'
          // value: '3'
        }, {
          text: '星期四',
          value: '星期四'
          // value: '4'
        }, {
          text: '星期五',
          value: '星期五'
          // value: '5'
        }, {
          text: '星期六',
          value: '星期六'
          // value: '6'
        }, {
          text: '星期日',
          value: '星期日'
          // value: '7'
        }
      ],
      startList: [],
      // startList: [{'text': '08:00', 'value': '08:00'}, {'text': '08:15', 'value': '08:15'}, {'text': '08:30', 'value': '08:30'}, {'text': '08:45', 'value': '08:45'}, {'text': '09:00', 'value': '09:00'}, {'text': '09:15', 'value': '09:15'}, {'text': '09:30', 'value': '09:30'}, {'text': '09:45', 'value': '09:45'}, {'text': '10:00', 'value': '10:00'}, {'text': '10:15', 'value': '10:15'}, {'text': '10:30', 'value': '10:30'}, {'text': '10:45', 'value': '10:45'}, {'text': '11:00', 'value': '11:00'}, {'text': '11:15', 'value': '11:15'}, {'text': '11:30', 'value': '11:30'}, {'text': '11:45', 'value': '11:45'}, {'text': '12:00', 'value': '12:00'}, {'text': '12:15', 'value': '12:15'}, {'text': '12:30', 'value': '12:30'}, {'text': '12:45', 'value': '12:45'}, {'text': '13:00', 'value': '13:00'}, {'text': '13:15', 'value': '13:15'}, {'text': '13:30', 'value': '13:30'}, {'text': '13:45', 'value': '13:45'}, {'text': '14:00', 'value': '14:00'}, {'text': '14:15', 'value': '14:15'}, {'text': '14:30', 'value': '14:30'}, {'text': '14:45', 'value': '14:45'}, {'text': '15:00', 'value': '15:00'}, {'text': '15:15', 'value': '15:15'}, {'text': '15:30', 'value': '15:30'}, {'text': '15:45', 'value': '15:45'}, {'text': '16:00', 'value': '16:00'}, {'text': '16:15', 'value': '16:15'}, {'text': '16:30', 'value': '16:30'}, {'text': '16:45', 'value': '16:45'}, {'text': '17:00', 'value': '17:00'}, {'text': '17:15', 'value': '17:15'}, {'text': '17:30', 'value': '17:30'}, {'text': '17:45', 'value': '17:45'}, {'text': '18:00', 'value': '18:00'}, {'text': '18:15', 'value': '18:15'}, {'text': '18:30', 'value': '18:30'}, {'text': '18:45', 'value': '18:45'}, {'text': '19:00', 'value': '19:00'}, {'text': '19:15', 'value': '19:15'}, {'text': '19:30', 'value': '19:30'}, {'text': '19:45', 'value': '19:45'}],
      endList: [{'text': '08:15', 'value': '08:15'}, {'text': '08:30', 'value': '08:30'}, {'text': '08:45', 'value': '08:45'}, {'text': '09:00', 'value': '09:00'}, {'text': '09:15', 'value': '09:15'}, {'text': '09:30', 'value': '09:30'}, {'text': '09:45', 'value': '09:45'}, {'text': '10:00', 'value': '10:00'}, {'text': '10:15', 'value': '10:15'}, {'text': '10:30', 'value': '10:30'}, {'text': '10:45', 'value': '10:45'}, {'text': '11:00', 'value': '11:00'}, {'text': '11:15', 'value': '11:15'}, {'text': '11:30', 'value': '11:30'}, {'text': '11:45', 'value': '11:45'}, {'text': '12:00', 'value': '12:00'}, {'text': '12:15', 'value': '12:15'}, {'text': '12:30', 'value': '12:30'}, {'text': '12:45', 'value': '12:45'}, {'text': '13:00', 'value': '13:00'}, {'text': '13:15', 'value': '13:15'}, {'text': '13:30', 'value': '13:30'}, {'text': '13:45', 'value': '13:45'}, {'text': '14:00', 'value': '14:00'}, {'text': '14:15', 'value': '14:15'}, {'text': '14:30', 'value': '14:30'}, {'text': '14:45', 'value': '14:45'}, {'text': '15:00', 'value': '15:00'}, {'text': '15:15', 'value': '15:15'}, {'text': '15:30', 'value': '15:30'}, {'text': '15:45', 'value': '15:45'}, {'text': '16:00', 'value': '16:00'}, {'text': '16:15', 'value': '16:15'}, {'text': '16:30', 'value': '16:30'}, {'text': '16:45', 'value': '16:45'}, {'text': '17:00', 'value': '17:00'}, {'text': '17:15', 'value': '17:15'}, {'text': '17:30', 'value': '17:30'}, {'text': '17:45', 'value': '17:45'}, {'text': '18:00', 'value': '18:00'}, {'text': '18:15', 'value': '18:15'}, {'text': '18:30', 'value': '18:30'}, {'text': '18:45', 'value': '18:45'}, {'text': '19:00', 'value': '19:00'}, {'text': '19:15', 'value': '19:15'}, {'text': '19:30', 'value': '19:30'}, {'text': '19:45', 'value': '19:45'}, {'text': '20:00', 'value': '20:00'}],
      hasXiangmuShow: false,
      shaixuanPatient: [],
      shaixuandoctor: [],
      shaixuanXiangmu: [],
      datedaylist: [],
      teamList: [],
      patient_user_id: this.$route.query.patient_user_id,
      start_time: '',
      end_time: '',
      datedayShow: false,
      start_endShow: false,
      shaixuandoctorShow: false,
      shaixuanXiangmuShow: false,
      teamShow: false
    }
  },
  computed: {
    title () {
      let title = this.$route.query.title
      if (title) {
        document.title = title
      } else {
        title = '团队排班'
      }
      return title
    },
    time () {
      return function (text) {
        let list = []
        this.Tims.map((curr, index) => {
          const [star, end] = [curr, this.Tims[index + 1]]
          let obj = {
            startTime: star,
            endTime: end
          }
          if (this.Tims[index + 1]) {
            if (text == 'last') {
              list.unshift(obj)
            } else {
              list.push(obj)
            }
          }
        })
        return list
      }
    },
    // 前一天
    lastDate () {
      let nowDate = new Date(this.dateday)
      let date = this.Common.formatDate(new Date(nowDate.getTime() - this.lastCount * 24 * 60 * 60 * 1000).toLocaleDateString(), 'yyyy-mm-dd')
      return date
    },
    // 后一天
    nextDate () {
      let nowDate = new Date(this.dateday)
      let date = this.Common.formatDate(new Date(nowDate.getTime() + this.nextCount * 24 * 60 * 60 * 1000).toLocaleDateString(), 'yyyy-mm-dd')
      return date
    }
  },
  mounted () {
    this.$toast({
      message: '向左滑动查看更多',
      icon: 'like-o'
    })
    // 当前登录者
    this.getDocInfo()
    // 我加入的团队
    this.getMyteam()
    // 获取某天排班
    this.getDayPaiban()
  },
  methods: {
    filter () {
      this.tableData = []
      let dateday = ''
      let start_time = ''
      let doc_user_id = ''
      let doc_amount_id = ''
      let team_amount_id = ''
      this.datedaylist.forEach((curr, index) => {
        if (curr.select === true) {
          console.log(curr)
          dateday += curr.value + ','
        }
      })
      this.startList.forEach((curr, index) => {
        if (curr.select === true) {
          start_time += curr.value + ','
        }
      })
      this.shaixuandoctor.forEach((curr, index) => {
        if (curr.select === true) {
          doc_user_id += curr.value + ','
        }
      })
      this.shaixuanXiangmu.forEach((curr, index) => {
        if (curr.select === true) {
          if (curr.self) {
            doc_amount_id += curr.value + ','
          } else {
            team_amount_id += curr.value + ','
          }
        }
      })
      let team_id = ''
      if (this.team_id) {
        team_id = this.team_id
      }
      this.teamList.forEach((curr, index) => {
        if (curr.select === true) {
          team_id += curr.value + ','
          if (curr.value == -1) {
            doc_user_id += curr.doc_user_id + ','
          }
        }
      })
      if (dateday) {
        dateday = dateday.substring(0, dateday.length - 1)
      } else {
        dateday = this.dateday
      }
      if (doc_amount_id) {
        doc_amount_id = doc_amount_id.substring(0, doc_amount_id.length - 1)
      }
      if (team_amount_id) {
        team_amount_id = team_amount_id.substring(0, team_amount_id.length - 1)
      }
      if (doc_user_id) {
        doc_user_id = doc_user_id.substring(0, doc_user_id.length - 1)
      }
      start_time = start_time.substring(0, start_time.length - 1)
      team_id = team_id.substring(0, team_id.length - 1)

      let start = ''
      let end = ''
      if (this.start_time && this.end_time) {
        start = this.start_time
        end = this.end_time
      }
      this.$http.findDocScheduleParam({
        dateday: dateday,
        start_time: start_time,
        doc_user_id: doc_user_id,
        team_id: team_id,
        doc_amount_id: doc_amount_id,
        team_amount_id: team_amount_id,
        patient_user_id: this.patient_user_id,
        del_tag: '0,0',
        dateday_begin: start,
        dateday_end: end
      })
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            let data = res.data.data

            data.map((item, i) => {
              let obj = {
                startTime: item.start_time,
                endTime: item.end_time,
                dateday: item.dateday,
                weekday: this.Common.week(item.weekday),
                patient_user_id: item.patient_user_id,
                patient_name: item.patient_name,
                list: [],
                team_id: item.team_id,
                name: '',
                doc_user_name: item.doc_user_name,
                doc_user_id: item.doc_user_id,
                del_tag: item.del_tag,
                id: item.id,
                datedayall: item.datedayall
              }
              if (item.team_id) { // 选的是团队
                obj.team_name = item.team_name
                obj.name = item.team_id
                obj.list = item.teamList
                // if (item.team_id == -1) { // 选的是个人
                //   obj.name = item.doc_user_id
                //   obj.list = item.docList
                // }
              }
              this.tableData.push(obj)
            })
            console.log(this.tableData)
            this.loadingShow = false
          } else {
            this.$toast(res.data.msg)
            this.loadingShow = false
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 获取患者
    getPaitents () {
      this.$set(this.row, 'optionPatient', [])
      let team_id = ''
      let doc_user_id = ''
      if (this.row.team_id) {
        // if (this.row.team_id == -1) {
        // } else {
        // }
        team_id = this.row.team_id
        doc_user_id = this.row.doc_user_id
      }
      this.$http.listPatientManage({team_id: team_id, doc_user_id: doc_user_id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            res.data.data.forEach((curr, index) => {
              let obj = {
                text: curr.name,
                value: curr.USER_ID
              }
              this.row.optionPatient.push(obj)
            })
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 更改患者
    changePaitent (val) {
      this.row.optionPatient.forEach((curr, index) => {
        if (curr.value == val) {
          this.row.patient_user_id = val
          this.row.patient_name = curr.text
        }
      })
      this.getPriceList('use')
    },
    renderHeader (h, {column}) { // h即为cerateElement的简写，具体可看vue官方文档
      return h(
        'span',
        [
          h('span', column.label),
          h('i', {
            class: 'el-icon-arrow-down',
            style: 'color:#fff;margin-left:5px;'
          })
        ]
      )
    },
    filterTagDayList (value, row, column) {
      return row.dateday === value
    },
    filterTagPatient (value, row, column) {
      return row.patient_name === value
    },
    filterTagDoctor (value, row, column) {
      return row.doc_user_name === value
    },
    // 项目筛选
    filterTagXiangmu (value, row, column) {
      let isTrue = false
      row.list.forEach((curr, index) => {
        if (curr.item_id == value) {
          isTrue = true
          return false
        }
      })
      return isTrue
    },
    // 获取患者筛选条件
    getPatientShaixuan (day, start, end) {
      this.shaixuanPatient = []
      this.shaixuandoctor = []
      this.shaixuanXiangmu = []
      this.startList = []
      this.schedule_typeList = []
      this.datedaylist = []
      this.teamList = []
      this.$http.findDocScheduleSelect({
        dateday: day,
        dateday_begin: start,
        dateday_end: end,
        team_id: this.team_id,
        patient_user_id: this.patient_user_id,
        del_tag: '0,0'
      })
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            let data = res.data.data
            data.plist.forEach((curr, index) => {
              let obj = {
                text: curr.patient_name,
                value: curr.patient_name
              }
              this.shaixuanPatient.push(obj)
            })
            data.dlist.forEach((curr, index) => {
              let obj = {
                text: curr.doc_user_name,
                value: curr.doc_user_id
              }
              this.shaixuandoctor.push(obj)
            })
            data.teamlist.forEach((curr, index) => {
              let obj = {
                text: curr.item_id,
                value: curr.id,
                self: 0
              }
              this.shaixuanXiangmu.push(obj)
            })
            data.doclist.forEach((curr, index) => {
              let obj = {
                text: curr.item_id,
                value: curr.item_id,
                self: 1
              }
              this.shaixuanXiangmu.push(obj)
            })
            data.startendlist.forEach((curr, index) => {
              let key = {
                text: curr.start_time + '~' + curr.end_time,
                value: curr.start_time
              }
              this.startList.push(key)
            })
            // data.typelist.forEach((curr, index) => {
            //   let key = {
            //     text: Number(curr.team_schedule_type) == 1 ? '对内' : Number(curr.team_schedule_type) == 2 ? '对外' : '',
            //     value: curr.team_schedule_type
            //   }
            //   this.schedule_typeList.push(key)
            // })
            data.datedaylist.forEach((curr, index) => {
              let key = {
                text: curr.dateday,
                value: curr.datedayall
              }
              this.datedaylist.push(key)
            })
            data.tlist.forEach((curr, index) => {
              let key = {
                text: curr.team_name,
                value: curr.team_id
              }
              if (curr.team_id == -1) {
                key.doc_user_id = curr.doc_user_id
              } else {
              }
              this.teamList.push(key)
            })
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    filterTag (value, row, column) {
      return row.weekday === value
    },
    filterTagZhan (value, row, column) {
      let isTrue = false
      if (value == 1 && !row.patient_user_id) {
        isTrue = true
      } else if (value == 2 && row.patient_user_id) {
        isTrue = true
      }
      return isTrue
    },
    filterTagStart (value, row, column) {
      let rowData = row.startTime + '~' + row.endTime
      return rowData === value
    },
    filterTagSchedule_type (value, row, column) {
      return Number(row.team_schedule_type) === Number(value)
    },
    filterTagEnd (value, row, column) {
      return row.endTime === value
    },
    moreDateConfirm (date) {
      let [start, end] = date
      this.moreDateShow = false
      start = this.Common.formatDate(start, 'yyyy-mm-dd')
      end = this.Common.formatDate(end, 'yyyy-mm-dd')
      this.start_time = start
      this.end_time = end
      this.getDayPaiban('', '', start, end)
      this.shaixuanDate = start + '至' + end
    },
    tableHeader (column, event) {
      console.log(column)
      if (column.property == 'dateday') {
        this.datedayShow = true
      } else if (column.property == 'startTime') {
        this.start_endShow = true
      } else if (column.property == 'doc_user_name') {
        this.shaixuandoctorShow = true
      } else if (column.property == 'list') {
        this.shaixuanXiangmuShow = true
      } else if (column.property == 'name') {
        this.teamShow = true
      }
    },
    // 下拉刷新
    onRefresh () {
      // if (this.loadingShow == true) {
      // } else {
      //   setTimeout(() => {
      //     // Toast('刷新成功')
      //     this.isLoading = false
      //     this.lastCount++
      //     this.getDayPaiban('last')
      //   }, 1000)
      // }
    },
    // 获取某天排班
    getDayPaiban (text, update, starDate, endDate) {
      this.loadingShow = true
      if (text) {
      } else {
        this.tableData = []
      }
      let day, start, end
      // if (text == 'last') {
      //   day = this.lastDate
      // } else if (text == 'next') {
      //   day = this.nextDate
      // } else {
      //   day = this.dateday
      // }
      day = this.dateday
      if (starDate) {
        if (starDate == endDate) {
          day = starDate
        } else {
          this.dateday = ''
          day = null
          start = starDate
          end = endDate
        }
      }
      let doc_user_id = ''
      if (this.doc_user_id) {
        doc_user_id = this.doc_user_id
      }
      // 获取筛选 患者信息
      this.getPatientShaixuan(day, start, end)
      this.$http.findDocScheduleParam({
        dateday: day,
        dateday_begin: start,
        dateday_end: end,
        team_id: this.team_id,
        del_tag: '0,0',
        patient_user_id: this.patient_user_id,
        doc_user_id: doc_user_id
      })
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            let data = res.data.data
            if (update == 'update') {
              data.map((curr, index) => {
                this.tableData.map((item, i) => {
                  if (item.id == curr.id && curr.start_time == item.startTime) {
                    item.id = curr.id
                    item.del_tag = curr.del_tag
                    item.patient_user_id = curr.patient_user_id
                    item.patient_name = curr.patient_name
                    if (curr.team_id) { // 选的是团队
                      curr.team_name = curr.team_name
                      item.team_id = curr.team_id
                      item.name = curr.team_id
                      item.list = curr.teamList
                      if (curr.team_id == -1) { // 选的是个人
                        item.doc_user_id = curr.doc_user_id
                        item.name = curr.doc_user_id
                        item.list = curr.docList
                      }
                    }
                  }
                })
              })
            } else {
              data.map((item, i) => {
                let obj = {
                  startTime: item.start_time,
                  endTime: item.end_time,
                  dateday: item.dateday,
                  weekday: this.Common.week(item.weekday),
                  patient_user_id: item.patient_user_id,
                  patient_name: item.patient_name,
                  team_schedule_type: item.team_schedule_type,
                  list: [],
                  team_id: item.team_id,
                  name: '',
                  doc_user_id: item.doc_user_id,
                  del_tag: item.del_tag,
                  id: item.id,
                  doc_user_name: item.doc_user_name,
                  datedayall: item.datedayall
                }
                if (item.team_id) { // 选的是团队
                  obj.team_name = item.team_name
                  obj.team_id = item.team_id
                  obj.name = item.team_id
                  obj.list = item.teamList
                  if (item.team_id == -1) { // 选的是个人
                    obj.doc_user_id = item.doc_user_id
                    obj.name = item.doc_user_id
                    obj.list = item.docList
                  }
                }
                this.tableData.push(obj)
              })
            }
            console.log(this.tableData)
            this.loadingShow = false
          } else {
            this.$toast(res.data.msg)
            this.loadingShow = false
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 选择 状态
    selectOpen (action, index) {
      this.row.team_schedule_type = action.type
      this.getPriceList('use')
    },
    // 选择 项目 确认
    priceConfirm () {
      this.save()
      this.xiangmuShow = false
    },
    // 选择已有项目
    clickHasPrice (item) {
      if (item.select) {
        item.select = !item.select
      } else {
        this.$set(item, 'select', true)
      }
    },
    // 点击 选择价格
    clickPrice (item) {
      if (item.leiType == 'all') {
        this.priceList.map((curr, index) => {
          if (curr.item_type == item.item_type) {
            this.$set(curr, 'select', true)
          }
        })
      } else {
        if (item.select) {
          item.select = null
        } else {
          this.$set(item, 'select', true)
        }
      }
    },
    // 获取服务项目
    getPriceList (text) {
      this.priceList = []
      let arr = [
        {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 1
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 2
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 3
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 4
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 5
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 6
        }, {
          item_id: '全选',
          leiType: 'all',
          checked_id: true,
          item_type: 7
        }
      ]
      if (this.row.team_id) {
        this.$http.findTeamPrice({team_id: this.row.team_id, is_check_amount: 1})
          .then(res => {
            console.log(res)
            if (res.data.status === 'success') {
              this.priceList = res.data.data
              arr.map((curr, index) => {
                this.priceList.unshift(curr)
              })
              this.row.list.map((item, i) => {
                this.priceList.map((curr, index) => {
                  if (item.id == curr.id) {
                    this.$set(curr, 'select', true)
                  }
                })
              })
              if (text == 'use') {
                this.save()
              }
            } else {
              Toast(res.data.msg)
            }
          })
          .catch(err => {
            console.log(err)
            Toast('您的网络有些拥挤，请稍后再试')
          })
      } else if (this.row.doc_user_id) {
        this.$http.findDocAmount()
          .then(res => {
            console.log(res)
            if (res.data.status === 'success') {
              this.priceList = res.data.data
              arr.map((curr, index) => {
                this.priceList.unshift(curr)
              })
              this.row.list.map((item, i) => {
                this.priceList.map((curr, index) => {
                  if (item.id == curr.id) {
                    this.$set(curr, 'select', true)
                  }
                })
              })
              if (text == 'use') {
                this.save()
              }
            } else {
              Toast(res.data.msg)
            }
          })
          .catch(err => {
            console.log(err)
            Toast('您的网络有些拥挤，请稍后再试')
          })
      } else {
        if (text == 'use') {
          this.save()
        }
      }
    },
    // 点击选中团队或个人
    changeTeam (value) {
      this.optionGuishu.map((curr, index) => {
        if (value == curr.value) {
          if (curr.type == 'team') { // 选团队
            this.row.team_id = curr.value
            this.row.doc_user_id = ''
          } else if (curr.type == 'doc') { // 选医生
            this.row.doc_user_id = curr.value
            this.row.team_id = ''
          }
        }
      })
      this.getPriceList('use')
    },
    // 登录者信息
    getDocInfo () {
      // this.$http.minidoctorDetail({doc_user_id: this.userid})
      //   .then(res => {
      //     console.log(res)
      //     if (res.data.status === 'success') {
      //       let data = res.data.data
      //       let obj = {
      //         text: data.NICK_NAME,
      //         value: data.USER_ID,
      //         type: 'doc',
      //         icon: require('../../../assets/radio/yisheng.png')
      //       }
      //       this.optionGuishu.push(obj)
      //     }
      //   })
      //   .catch(err => {
      //     console.log(err)
      //   })
    },
    // 点击单元格
    handle (row, column, event, cell) {
      this.row = row
      // var oDate1 = new Date(new Date()).getTime()
      // var oDate2 = new Date(this.row.datedayall).getTime()
      // if (oDate1 > oDate2) {
      //   this.$toast('历史数据不可修改')
      //   return false
      // } else if (column.property == 'patient_user_id') {
      //   this.getPaitents()
      // } else if (column.property == 'list') {
      //   if (this.row.list.length > 0) {
      //     this.hasXiangmuShow = true
      //     this.row.list.forEach((curr, index) => {
      //       this.$set(curr, 'select', true)
      //     })
      //   } else {
      //     this.xiangmuShow = true
      //     this.getPriceList()
      //   }
      // }
    },
    handleSelectionChange (val) {
      this.selectList = val
    },
    // 我加入的团队
    getMyteam () {
      this.$http.TeamList({team_type: 4})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            res.data.data.map((curr, index) => {
              let obj = {
                text: curr.team_name,
                value: curr.team_id,
                type: 'team',
                icon: require('../../../assets/radio/tuandui.png')
              }
              this.optionGuishu.push(obj)
            })
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 保存
    save (list) {
      let obj = {
        del_tag: '0' // 删除标记
      }
      if (this.row.del_tag) {
        obj.del_tag = this.row.del_tag.toString()
      }
      if (this.row.patient_user_id) {
        obj.inquiry_id = '-1'
        obj.patient_user_id = this.row.patient_user_id
        obj.patient_name = this.row.patient_name
      } else {
        obj.patient_user_id = ''
        obj.patient_name = ''
      }
      if (this.row.id) {
        obj.id = this.row.id.toString()
      } else {
        obj.id = '0'
      }
      if (this.row.team_id) {
        obj.team_id = this.row.team_id.toString()
      }
      if (this.row.team_schedule_type) {
        obj.team_schedule_type = this.row.team_schedule_type
      }
      obj.list = []
      if (list) {
        list.forEach((curr, index) => {
          if (curr.select == true) {
            let arr = {
              amount_type: curr.amount_type,
              team_amount_id: curr.id
            }
            obj.list.push(arr)
          }
        })
      } else {
        this.priceList.forEach((curr, index) => {
          if (curr.leiType) {
          } else {
            if (curr.select) {
              let arr = Object
              if (this.row.team_id) {
                arr = {
                  amount_type: curr.item_type,
                  team_amount_id: curr.id
                }
              } else if (this.row.doc_user_id) {
                arr = {
                  amount_type: curr.item_type,
                  doc_amount_id: curr.id
                }
              }
              obj.list.push(arr)
            }
          }
        })
      }
      this.$http.saveDocSchedule(obj)
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            let rowDate = new Date(this.row.dateday)
            let NowDate = new Date(this.dateday)
            if (rowDate.getTime() < NowDate.getTime()) {
              // 获取某天排班
              this.getDayPaiban('last', 'update')
            } else if (rowDate.getTime() > NowDate.getTime()) {
              // 获取某天排班
              this.getDayPaiban('next', 'update')
            } else {
              this.getDayPaiban()
            }
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },

    // 返回
    back () {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style scoped >
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  width: 33%;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  /*margin-right: 15px;*/
  margin-right: 5px;
}
.div:nth-child(2){
  justify-content: center;
}
.div:nth-child(3){
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.pop_content{
  display: flex;
  height: calc(100% - 44px);
}
.pop_content ul{
  height: 100%;
  overflow: auto;
}
.pop_content ul li{
  min-height: 44px;
  display: flex;
  align-items: center;
  padding-left: 10px;
  box-sizing: border-box;
}
.pop_left {
  background: #F5F5F5;
  box-sizing: border-box;
}
.pop_right li {
  border-bottom: 1px solid #E5E5E5;
  display: flex;
  justify-content: space-between;
}
.pop_select{
  background: #FFFFFF!important;
}
.selectImg{
  width: 16px;
  height: 16px;
}
/deep/ .van-dropdown-menu__bar{
  box-shadow: none;
}
/deep/
.el-table th>.cell.highlight {
  color: #333333;
}
/deep/ .el-table__column-filter-trigger i{
  color: #fff;
}
/deep/ .el-table-filter__content{
  height: 50vh;
  overflow: auto;
}

.riqiSelect{
  width: 100%;
  height: 44px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  padding: 0 10px;
  box-sizing: border-box;
  color: #1da4f2;
}
.riqiSelect span{
  display: flex;
  align-items: center;
}
.hengGang{
  display: block;
  width: 2px;
  border-radius: 1px;
  height: 16px;
  background: #1DA4F2;
  margin-right: 5px;
}
</style>
<style>
.el-table-filter__content {
  max-height: 300px;
  overflow: auto;
}
.el-table__column-filter-trigger i {
  color: #fff;
  font-size: 17px;
}
.el-checkbox__label{
  font-size: 15px;
}
.el-table-filter__bottom button{
  font-size: 15px;
}
.van-dropdown-menu__title::after {
  position: absolute;
  top: 50%;
  right: -4px;
  margin-top: -5px;
  border: 3px solid;
  border-color: transparent transparent #333#333;
  -webkit-transform: rotate(
    -45deg
  );
  -ms-transform: rotate(-45deg);
  transform: rotate(
    -45deg
  );
  opacity: .8;
  content: '';
}
</style>
